package com.chixing.ih.module.task.controller;


import com.chixing.ih.json.ResponseData;
import com.chixing.ih.module.task.pojo.DTO.ProgressTaskDTO;
import com.chixing.ih.module.task.pojo.ProgressTask;
import com.chixing.ih.module.task.service.impl.ProgressTaskServiceImpl;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 目的:
 *
 * @author ：zcw
 * @version: 1.0  2020/10/3 17:28
 */
@RestController
@RequestMapping("progressTask")
public class ProgressTaskController {

    @Autowired
    private ProgressTaskServiceImpl progressTaskService;

    @ApiOperation(value = "获取该任务的全部任务进度接口", notes = "获取该任务的全部任务进度")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", value = "任务id", required = true, dataType = "Long")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
            @ApiResponse(code = 400, message = "查询失败"),
            @ApiResponse(code = 500, message = "程序内部代码出现问题")
    })
    @GetMapping("taskProgresses/{taskId}")
    public Map<String, Object> findAll(@PathVariable("taskId") Long taskId) {
        List<ProgressTaskDTO> list = progressTaskService.findAll(taskId);
        if (list.size() > 0) {
            return ResponseData.REP_GET_SUCCESS(list);
        }
        return ResponseData.REP_INVALID_ERROR();
    }


    @ApiOperation(value = "获取任务进度详情接口", notes = "获取任务进度详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "progressTaskId", value = "任务进度id", required = true, dataType = "Long")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
            @ApiResponse(code = 400, message = "查询失败"),
            @ApiResponse(code = 500, message = "程序内部代码出现问题")
    })
    @GetMapping("taskProgress/{progressTaskId}")
    public Map<String, Object> findOne(@PathVariable("progressTaskId") Long progressTaskId) {
        ProgressTask progressTask = progressTaskService.findOne(progressTaskId);
        if (null != progressTask) {
            return ResponseData.REP_GET_SUCCESS(progressTask);
        }
        return ResponseData.REP_INVALID_ERROR();
    }


    @ApiOperation(value = "添加任务进度接口", notes = "添加任务进度")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", value = "任务id", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "subTask", value = "提交内容", required = true, dataType = "String")
    })
    @ApiResponses({
            @ApiResponse(code = 201, message = "查询成功"),
            @ApiResponse(code = 400, message = "查询失败"),
            @ApiResponse(code = 500, message = "程序内部代码出现问题")
    })
    @PostMapping("taskProgress")
    public Map<String, Object> insertOne(@RequestBody ProgressTaskDTO progressTask) {
        if (progressTaskService.insertOne(progressTask) > 0) {
            return ResponseData.REP_CREATED_SUCCESS();
        }
        return ResponseData.REP_INVALID_ERROR();
    }


}
